package com.platform.modules.app.controller.dto;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.platform.modules.mall.entity.MallGoodsEntity;
import com.platform.modules.mall.entity.MallSkuGroupEntity;
import com.platform.modules.mall.entity.MallSkuUniqueInfoEntity;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class SkuDto {
    private static final long serialVersionUID = 2L;
    private JSONArray specifications = new JSONArray();
    private JSONArray difference = new JSONArray();

    public SkuDto(MallGoodsEntity info, List<MallSkuUniqueInfoEntity> skuUniqueInfoEntities) {
        List<TreeDto> tree = new ArrayList<>(5);
        List<JSONObject> list = new ArrayList<>(5);
        if (info.getSkuGroupEntities() != null && info.getSkuGroupEntities().size() > 0) {
            int size = info.getSkuGroupEntities().size();
            for (int i = 0; i < size; i++) {
                MallSkuGroupEntity skuGroupEntity = info.getSkuGroupEntities().get(i);
                TreeDto treeDto = new TreeDto(skuGroupEntity);
                specifications.add(treeDto);
            }
        }
        for (MallSkuUniqueInfoEntity skuUniqueInfoEntity : skuUniqueInfoEntities) {
            ListDto listDto = new ListDto(skuUniqueInfoEntity);
            JSONObject jsonObject = (JSONObject) JSONObject.toJSON(listDto);
            difference.add(jsonObject);
        }
    }

}
